<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">

      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>

      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>

      <el-table-column
        prop="phone"
        label="电话"
        width="180">
      </el-table-column>

      <el-table-column
        prop="email"
        label="邮箱">
      </el-table-column>

      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>

      <el-table-column
        prop="createTime"
        label="创建时间">
      </el-table-column>
    </el-table>

    <!--分页-->
    <el-pagination
      background
      align="right"
      layout="prev, pager, next"
      :total="totals"
      :current-page="currentPage"
      :page-size="pageSize"
      @current-change="pageList">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'User2',
  data () {
    return {
      totals:0,
      currentPage:1,
      pageSize:5,
      tableData: []
    }
  },
  mounted() {
    //第一次初始化的时候发送axios请求
    this.list()
  },
  methods:{
    pageList(current){
      //后面点击页码的时候 发送axios请求
      this.currentPage=current;
      this.list();
    },
    list(){
      //发送axios请求将数据赋值到tableData上
      //1.安装axios
      //2.在main.js中引入axios
        //引入
        //设置请求地址的基础路径
        //将axios作为vue的扩展属性--即将axios改名为$http:Vue.prototype$http = axios
      this.$http.post("/user/list",{"currentPage":this.currentPage,"pageSize":this.pageSize})
      .then(result=>{
        //代表请求成功
        this.tableData = result.data.data;
        this.totals = result.data.totals;
      })
      .catch(result=>{
          //代表请求失败
          alert("出错了")
      })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
